﻿using System;
using Entities.DataBase.Persistent;

namespace Entities.DataBase.Obj {


    public class CustomerUpdator {

        public string CustomerId    { get; set; }
        public string Name          { get; set; }
        public string CName         { get; set; }
        public string Email1        { get; set; }
        public string Email2        { get; set; }
        public int?   Sex           { get; set; }
        public string PhoneNumber1  { get; set; }
        public string PhoneNumber2  { get; set; }
        public string Address1      { get; set; }
        public string Address2      { get; set; }

        public void UpdateCustomer(Customer customer) {
            if (string.IsNullOrEmpty(CustomerId) || !customer.Id.Equals(CustomerId)) {
                throw new Exception("Customer  Id not match.");
            }

            customer.DateUpdated = DateTime.UtcNow;
            if (!string.IsNullOrEmpty(Name) && !customer.Name.Equals(Name)) {
                customer.Name = Name;
            }

            if (!string.IsNullOrEmpty(CName) && !customer.CName.Equals(CName)) {
                customer.CName = CName;
            }

            if (!string.IsNullOrEmpty(Email1) && !customer.CName.Equals(Email1)) {
                 customer.Email1 = Email1;
            }

            if (!string.IsNullOrEmpty(Email2) && !customer.CName.Equals(Email2)) {
                customer.Email2 = Email2;
            }

            if (!string.IsNullOrEmpty(PhoneNumber1) && !customer.CName.Equals(PhoneNumber1)) {
                customer.PhoneNumber1 = PhoneNumber1;
            }

            if (!string.IsNullOrEmpty(Address1) && !customer.CName.Equals(Address1)) {
                customer.Address1 = Address1;
            }

            if (!string.IsNullOrEmpty(Address2) && !customer.CName.Equals(Address2)) {
                customer.Address2 = Address2;
            }

            if (Sex != null) {
                customer.Sex = (int)Sex;
            }
        }
    }
}